local fufeng = fk.CreateSkill{
  name = "hanqing__fufeng",
  tags = { Skill.Switch },
}

Fk:loadTranslationTable{
  ["hanqing__fufeng"] = "伏锋",
  [":hanqing__fufeng"] = "转换技，①出牌阶段，你可以重铸任意张非♠牌；②弃牌阶段开始时，你可以明置任意张【杀】，这些牌视为不计入"..
  "手牌上限的♠A【影】。",

  [":hanqing__fufeng_yang"] = "转换技，<font color=\"#E0DB2F\">①出牌阶段，你可以重铸任意张非♠牌；</font>"..
  "<font color=\"gray\">②弃牌阶段开始时，你可以明置任意张【杀】，这些牌视为不计入手牌上限的♠A【影】。</font>",
  [":hanqing__fufeng_yin"] = "转换技，<font color=\"gray\">①出牌阶段，你可以重铸任意张非♠牌；</font>"..
  "<font color=\"#E0DB2F\">②弃牌阶段开始时，你可以明置任意张【杀】，这些牌视为不计入手牌上限的♠A【影】。</font>",

  ["#hanqing__fufeng-yang"] = "伏锋：你可以重铸任意张非♠牌",
  ["#hanqing__fufeng-yin"] = "伏锋：你可以明置任意张【杀】，这些牌视为不计入手牌上限的♠A【影】",
  ["@@hanqing__fufeng-inhand"] = "伏锋",
}

local DIY = require "packages/diy_utility/diy_utility"

fufeng:addEffect("active", {
  anim_type = "switch",
  prompt = "#hanqing__fufeng-yang",
  min_card_num = 1,
  target_num = 0,
  can_use = function(self, player)
    return player:getSwitchSkillState(fufeng.name, false) == fk.SwitchYang
  end,
  card_filter = function(self, player, to_select)
    return Fk:getCardById(to_select).suit ~= Card.Spade
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    room:recastCard(effect.cards, player, fufeng.name)
  end,
})

fufeng:addEffect(fk.EventPhaseStart, {
  anim_type = "switch",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(fufeng.name) and player.phase == Player.Discard and
    player:getSwitchSkillState(fufeng.name, false) == fk.SwitchYin
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local all_cards = table.filter(player:getCardIds("h"), function (id)
      local card = Fk:getCardById(id)
      return card.trueName == "slash" and not table.contains(DIY.getShownCards(player), id)
    end)
    local cards = room:askToCards(player, {
      min_num = 1,
      max_num = 999,
      include_equip = false,
      skill_name = fufeng.name,
      pattern = tostring(Exppattern{ id = all_cards }),
      prompt = "#hanqing__fufeng-yin",
      cancelable = true,
    })
    if #cards > 0 then
      event:setCostData(self, {cards = cards})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = event:getCostData(self).cards
    for _, id in ipairs(cards) do
      room:setCardMark(Fk:getCardById(id), "@@hanqing__fufeng-inhand", 1)
    end
    DIY.showCards(player, cards)
  end,
})

fufeng:addEffect("filter", {
  card_filter = function(self, to_select, player)
    return to_select:getMark("@@hanqing__fufeng-inhand") > 0
  end,
  view_as = function(self, player, to_select)
    return Fk:cloneCard("stab__slash", Card.Spade, 1)
  end,
})

fufeng:addEffect("maxcards", {
  exclude_from = function(self, player, card)
    return card:getMark("@@hanqing__fufeng-inhand") > 0
  end,
})

return fufeng
